import store from '@/store';
import { listUser, getUserListByRole } from '@/api/system/user';
import { UserVO } from '@/api/system/user/types';

export const useCRMStore = defineStore('crm', () => {
  const userList = ref<UserVO[]>([]);
  /** 获取用户列表 */
  const getUsers = async (): Promise<void> => {
    const { rows } = await listUser({ pageNum: 1, pageSize: 999 });
    userList.value = rows;
  };
  const roleKeyUserList = ref<UserVO[]>([]);
  /** 根据roleKey获取用户 */
  const getUserListByRoleKey = async (roleKey: string): Promise<void> => {
    const { data } = await getUserListByRole(roleKey);
    roleKeyUserList.value = data;
  };
  return {
    userList,
    getUsers,
    roleKeyUserList,
    getUserListByRoleKey
  };
});

export default useCRMStore;
